define([
  'vue',
  'el-cache',
  'text!' +
  ELMP.resource('components/review-team/index.html', 'tmzk_workflow'),
  // ELMP.url('apps/resource/lib/components/vue-collapse/index.js'),
  ELMP.resource('components/vue-collapse/index.js', 'lib'),

], function (Vue, elCache, template, vueCollapse) {
  return {
    components: {
      vueCollapse,
    },
    template,
    props: {
      TableData: {
        type: Array,
        default: [],
      },
      isDisabled: {
        type: Boolean,
        default: false,
      },
      header: { type: String, default: '' },
    },
    data() {
      return {
        reviewName: "",
        changeTable: []
      }
    },
    created() { },
    mounted() {
      // 渲染选人组件
    },
    methods: {
      querySearchAsync(val, callback) {
        if (val === "") {
          callback([])

        } else {
          $.el.get({
            url: ELMP.url('/org/v1/users/fuzzy'),
            // 接口参数
            params: {
              fuzzyQueryCondition: val
            },
            success: (resp) => {
              if (resp && resp.code == 200) {
                let results = resp.res.data.records.map(c => {
                  c.value = c.displayName + `(${c.code})`
                  return c
                });
                callback(results)
              }
            },
            error: (e) => {
              $.msg.close(), $.msg.error(e.message);
            },
          });
        }

      },
      // 表格搜索框
      handleSelect(val) {
        let newVal = { id: val.id, displayName: val.displayName, orgName: val.orgName }  //数据优化
        this.TableData.find(c => c.id === val.id) ? $.msg.tips('不能重复添加!') : this.TableData.push(newVal)
        this.reviewName = ""

      },
      // 表格选择
      handleSelectionChange(val) {

        this.changeTable = val
      },
      // 删除数据
      handleDel() {
        const that = this
        if (this.changeTable.length > 0) {
          $.msg.confirm($.i18n.get('确定删除吗!'), function () {
            let arr = []
            that.changeTable.forEach((item, index) => {
              that.TableData.forEach((c,indexl) => {
                console.log(item.id, c.id);
                if (item.id == c.id) {
                  that.TableData.splice(indexl, 1)
                }
              });
            });
            $.msg.success('删除成功！')
          })
        } else {
          $.msg.tips('请选择要删除的数据!')
        }


      },
      setTableData(arr, disabled = false) {
        console.log(arr, 'arr');
        this.isDisabled = disabled
        this.TableData = arr
      },
      getTableData(isValid) {
        return new Promise((r, j) => {
          if (!isValid) {
            r(this.TableData)
          } else {
            if (this.TableData.length > 0) {
              r(this.TableData)
            } else {
              $.msg.tips('评审专家组不能为空!')
              j()
            }

          }

        })
      },
    },
  }
})
